package mcsm.DataBaseIntegration;

import java.sql.SQLException;
import java.sql.Statement;

import mcsm.DataBaseInterface.EditOperation;

import Stragety.SingleGoodsStragety;

public class EditGoodsPreferential implements EditOperation {

	private SingleGoodsStragety goodsPreferential;
	
	public EditGoodsPreferential(SingleGoodsStragety goodsPreferential) {
		this.goodsPreferential = goodsPreferential;
	}

	@Override
	public Boolean connect(Statement statement) {
		boolean isOK = true;
		String[] edit = edit();
		for(int i = 0; i < edit.length; i++) {
			try {
				statement.executeUpdate(edit[i]);
			} catch (SQLException e) {
				isOK = false;
				e.printStackTrace();
			}
		}
		return isOK;
	}

	@Override
	public String[] edit() {
		String id = goodsPreferential.getID();
		String giftID = goodsPreferential.getGiftID();
		int giftAmount = goodsPreferential.getGiftQuantity();
		double discount = goodsPreferential.getDiscount();
		String fromDate= goodsPreferential.getStartTime();
		String toDate = goodsPreferential.getEndTime();
		String desc  = goodsPreferential.getDescription();
		String[] sql = new String[6];
		sql[0] = "update sumPreferential set giftID = '" + giftID + "' where id = " + id;
		sql[1] = "update sumPreferential set giftAmount = " + giftAmount + " where id = " + id;
		sql[2] = "update sumPreferential set discount = " + discount + " where id = " + id;
		sql[3] = "update sumPreferential set fromDate = '" + fromDate + "' where id = " + id;
		sql[4] = "update sumPreferential set toDate = '" + toDate + "' where id = " + id;
		sql[5] = "update sumPreferential set description = '" + desc + "' where id = " + id;
		return sql;
	}

}
